package com.vmj.instructions.constants;

import com.vmj.heap.RuntimeConstantPool;
import com.vmj.instructions.base.Index16Instruction;
import com.vmj.rtda.Frame;
import com.vmj.rtda.OperandStack;

/**
 * Created by yangshoujun on 2017/8/27 下午12:35.
 */
public class Ldc2w extends Index16Instruction {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        RuntimeConstantPool cp = frame.getMethod().getClazz().getRuntimeConstantPool();
        Object val = cp.getConstant(getIndex()).getValue();
        if(val instanceof Long) {
            stack.pushLong((Long) val);
        } else if(val instanceof Double) {
            stack.pushDouble((Double) val);
        } else {
            throw new RuntimeException("java.lang.ClassFormatError");
        }
    }
}
